<!-- 工术隐私政策组件 -->
<template>
	<view class="container" v-if="isAgreed">
		<!-- 遮罩层 -->
		<view class="mask" @click="closePopup"></view>

		<!-- 弹窗主体 -->
		<view class="popup-container">
			<!-- 弹窗头部 -->
			<view class="popup-header">
				<text class="title">工术光电用户服务协议和隐私政策</text>
				<uni-icons type="closeempty" class="close-icon" @click="closePopup" size="20"></uni-icons>
			</view>

			<!-- 协议内容区 -->
			<scroll-view class="content" scroll-y>
				<view class="content-view" v-html="data.content">
					
				</view>
			</scroll-view>

			<!-- 底部按钮区 -->
			<view class="btn-group">
				<button class="agree-btn" @click="handleAgree">同意并继续</button>
			</view>
		</view>
	</view>
</template>

<script>
	var db = uniCloud.database();
	export default {
		name: "popup",
		data() {
			return {
				data:{}
			}
		},
		props:{
			isAgreed: {
				type: Boolean, // 数字类型
				required: true, // 必填项
				default: false // 默认值
			},
		},
		mounted(){
			this.getTerms();
		},
		methods: {
			//获取用户协议
			getTerms(){
				db.collection('article').where({type:'terms'}).field('_id,type,content').get({getOne:true}).then(res=>{
					this.data = res.result.data;
				});
			},
			// 关闭弹窗
			closePopup() {
				this.$emit('popupAgreed', 'closePopup')
			},

			// 同意协议处理
			handleAgree() {
				// 1. 记录用户同意状态
				uni.setStorageSync('isUserAgreed', true);
				this.$emit('popupAgreed', 'handleAgree')

				// 2. 显示加载提示
				// uni.showLoading({
				// 	title: '正在处理...',
				// 	mask: true
				// });

				// 3. 模拟网络请求
				// setTimeout(() => {
				// 	uni.hideLoading();

				// 	// 4. 跳转到首页或注册成功页
				// 	uni.reLaunch({
				// 		url: '/pages/index/index'
				// 	});
				// }, 1000);
			}
		}
	}
</script>

<style scoped>
	.container {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 9999;
	}

	.mask {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.6);
	}

	.popup-container {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 70%;
		max-height: 80%;
		background-color: #fff;
		border-radius: 16px;
		overflow: hidden;
	}

	.popup-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		/* padding: 0 30px; */
		border-bottom: 2rpx solid #f5f5f5;
	}

	.title {
		font-size: 14px;
		font-weight: bold;
		color: #333;
		padding-left: 30px;
	}

	.close-icon {
		width: 40px;
		height: 40px;
		line-height: 40PX;
	}

	.content {
		height: 600px;
		font-size: 14px;
		color: #666;
		box-sizing: border-box;
	}

	.content-view {
		padding: 40px;
		text-align: justify;
		text-justify: inter-word;
		/* 支持英文单词间距调整 */
		text-align-last: left;
		/* 最后一行也两端对齐 */
	}

	.btn-group {
		padding: 20px;
		border-top: 2px solid #f5f5f5;
	}


	.agree-btn {
		width: 130px;
		height: 40px;
		line-height: 40px;
		text-align: center;
		font-size: 14px;
		color: #fff;
		background-color: #e4393c;
		border-radius: 8px;
	}
</style>